package com.smbms.controller;

import com.smbms.util.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 类名：ExceptiongController
 * 作者：小涛
 * 创建时间：2021/8/27-20:22
 * 功能：捕获所有Controller抛出的异常
 */
@ControllerAdvice
public class ExceptiongController {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Result exceptionHandler(Exception e){
        //打印异常信息
        e.printStackTrace();
        //响应数据
        return new Result(false,"请求异常："+e.getMessage());
    }
}
